package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;


public class tagTable implements Serializable {

    /*分析项目*/
    private String project;

    /*内容*/
    private LinkedList<String> content = new LinkedList<>();

    /*分析要求*/
    private LinkedList<String> require = new LinkedList<>();

    /*所在目录*/
    private LinkedList<String> directories = new LinkedList<>();

    /*集合长度*/
    private int length;

    @Override
    public String toString() {
        return "tagTable{" +
                "project='" + project + '\'' +
                ", content=" + content +
                ", require=" + require +
                ", directories=" + directories +
                ", length=" + length +
                '}';
    }

    public tagTable() {

    }

    public tagTable(String project, LinkedList<String> content, LinkedList<String> require, LinkedList<String> directories, int length) {
        this.project = project;
        this.content = content;
        this.require = require;
        this.directories = directories;
        this.length = length;
    }

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public LinkedList<String> getContent() {
        return content;
    }

    public void setContent(LinkedList<String> content) {
        this.content = content;
    }

    public LinkedList<String> getRequire() {
        return require;
    }

    public void setRequire(LinkedList<String> require) {
        this.require = require;
    }

    public LinkedList<String> getDirectories() {
        return directories;
    }

    public void setDirectories(LinkedList<String> directories) {
        this.directories = directories;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public tagTable(String str) {
        String[] splits = str.split("-");
        this.project = splits[0];
        String[] contents = splits[1].split(":");
        this.content = new LinkedList<>(Arrays.asList(contents));
        String[] requires = splits[2].split(":");
        this.require = new LinkedList<>(Arrays.asList(requires));
        String[] directories = splits[3].split(":");
        this.directories = new LinkedList<>(Arrays.asList(directories));
        this.length = contents.length;
    }

    public CoverTable toCoverTable() {
        CoverTable coverTable = new CoverTable();
        firstLine firstLine = new firstLine();
        firstLine.setRowspan(this.length);
        firstLine.setS1(this.project);
        firstLine.setS2(this.content.get(0));
        firstLine.setS3(this.require.get(0));
        firstLine.setS4(this.directories.get(0));
        coverTable.setFirstLine(firstLine);

        ArrayList<otherLine> otherLines = new ArrayList<otherLine>();
        for (int a = 1; a < length; a++) {
            otherLine otherLine = new otherLine();
            otherLine.setS1(this.content.get(a));
            otherLine.setS2(this.require.get(a));
            otherLine.setS3(this.directories.get(a));
            otherLines.add(otherLine);
        }
        coverTable.setOtherLines(otherLines);

        return coverTable;
    }
}
